package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.*;

import java.util.List;

/**
 * @author mjy
 * @date 2022/12/15
 * @description
 */
public class SetAppDisable implements Sender {


    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqAppDisable mqAppDisable = (MqAppDisable) mqMessage.getObject();
        String cmd = mqMessage.getType();
        String imei = mqAppDisable.getImei();
        int groupNum = mqAppDisable.getGroupNum();
        String commandNumber = mqAppDisable.getCommandNumber();
        int flag = mqAppDisable.getFlag();
        List<MqAppDisableTime> mqAppDisableTime = mqAppDisable.getMqAppDisableTime();
        String header = "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(imei).concat(",").
                concat(cmd).concat(",").concat(commandNumber).concat(",").concat(mqAppDisable.getPackageName()).concat(",").concat(String.valueOf(flag)).concat(",").concat(String.valueOf(groupNum));
        String tail = "#";
        String content = "";
        if (mqAppDisableTime != null && mqAppDisableTime.size() > 0) {
            for (MqAppDisableTime appDisableTime : mqAppDisableTime) {
                String startTime = appDisableTime.getStartTime();
                String endTime = appDisableTime.getEndTime();
                String cycle = appDisableTime.getCycle();
                content += ",".concat(startTime).concat(",").concat(endTime).concat(",").concat(cycle);
            }
        }
        content = header.concat(content).concat(tail);
        Command command = new Command();
        command.setImei(imei);
        command.setContent(content);
        command.setCmd(cmd);
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setCommandNumber(commandNumber);
        return command;
    }
}
